#include "PlayerManager.h"

#ifdef _WINDOWS
#include "winPlayer.h"
#else
#include "linuxPlayer.h"
#endif

CPlayerManager CPlayerManager::ins;

CPlayerManager::CPlayerManager(void)
    : m_player(NULL)
{

}

CPlayerManager::~CPlayerManager(void)
{

}


void CPlayerManager::CreatePlayer(const std::string &name)
{
    // first, delete old player
    // delete 0 is allright
    delete m_player;
    m_player = NULL;

#ifdef _WINDOWS
	if (name == "winamp")
	{
        m_player = new CWinAmpPlayer;
	}
	//else if (name == "itunes")
	//{
	//	return CPlayerPtr(new CITunesPlayer);
	//}
	else if (name == "wmp")
	{
        m_player = new CWmpPlayer;
	}
#else
	if (name == "xmms")
	{
        //m_player = new CXmmsPlayer;
        m_player = new CMpdPlayer;
	}
#endif
}


CPlayerManager& CPlayerManager::GetIns()
{
	return ins;
}

void CPlayerManager::ReleasePlayer()
{
	//m_player.reset();
    delete m_player;
    m_player = NULL;
}

bool CPlayerManager::IsPlayerOpen()
{
	if(m_player)
		return m_player->IsOpen();
	return false;
}

void CPlayerManager::SetPlayer(const std::string &name)
{
	CreatePlayer(name);
}
std::string CPlayerManager::GetMediaTitle()
{
	std::string res;
	if (m_player)
	{
		res = m_player->GetMediaTitle();
	}
	return res;
}
int CPlayerManager::GetCurrentTime()
{
	int res = -1;
	if (m_player)
	{
		res = m_player->GetCurrentTime();
	}
	return res;
}
